package com.android.li.temperature.bean;

import java.text.DecimalFormat;

public class ThermalFileNode {

    public String name;

    public String type;

    public String pathType;

    public String value;

    public String pathTemp;

    public double vauleDouble;

    public String valueStr;

    public boolean isTypeRead = true;

    public boolean isTempRead = true;

    public void formatTemparaturValue() {
        vauleDouble = Double.valueOf(value);

        vauleDouble = Math.abs(vauleDouble);
        while (vauleDouble > 1000) {
            vauleDouble = vauleDouble / 1000;
        }

        if (vauleDouble > 100) {
            vauleDouble = vauleDouble / 100.0;
        }

        vauleDouble = getOneDecimal(vauleDouble);

        valueStr = String.valueOf(vauleDouble);
    }

    /**
     * 将数据保留两位小数
     */
    public double getOneDecimal(double num) {
        DecimalFormat dFormat = new DecimalFormat("#.0");
        String dString = dFormat.format(num);
        return Double.valueOf(dString);
    }

    @Override
    public String toString() {
        if (type == null) {
            return name + " : " + valueStr;
        } else {
            return name + " ( " + type + " ) :" + valueStr + " ℃";
        }
    }
}
